﻿using System.Web.Mvc;
using Eacademy.Domain.Models;
using Eacademy.Domain.Abstractions;


namespace Eacademy.Domain.Services
{
    public class UserService : IUserService
    {
        private ModelStateDictionary _modelState;
        private IMentorRepository _mentorRepository;
        private IStudentRepository _studentRepository;
        private IUserRepository _userRepository;

        public UserService(ModelStateDictionary modelState, IMentorRepository mentorRepository, IUserRepository userRepository)
        {
            _modelState = modelState;
            _mentorRepository = mentorRepository;
            _userRepository = userRepository;
        }

        public UserService(ModelStateDictionary modelState, IStudentRepository studentRepository, IUserRepository userRepository)
        {
            _modelState = modelState;
            _studentRepository = studentRepository;
            _userRepository = userRepository;
        }

        public bool AddMentor(AdminMentorsViewModel adminMentorsViewModel)
        {
            if (_userRepository.UserExist(adminMentorsViewModel.Username))
            {
                _modelState.AddModelError("Username", "This username is already taken");
                return false;
            }
            else
            {

                if (_mentorRepository.AddMentor(adminMentorsViewModel) == null)
                {
                    return false;
                }

            }

            return true;
        }

        public bool AddStudent(AdminStudentsViewModel adminStudentsViewModel)
        {
            if (_userRepository.UserExist(adminStudentsViewModel.Username))
            {
                _modelState.AddModelError("Username", "This username is already taken");
                return false;
            }
            else
            {

                if (_studentRepository.AddStudent(adminStudentsViewModel) == null)
                {
                    return false;
                }

            }

            return true;
        }

    }
}